/**
 * The MIT License
 * <p>
 * Copyright (c) 2017
 */
package com.seelyn.flow.work;

/**
 * Default implementation of {@link WorkReport}.
 *
 * @author slacrey  (237242115@qq.com)
 */
public class DefaultWorkReport implements WorkReport {

    private WorkStatus status;
    private Throwable error;

    private DefaultWorkReport(WorkStatus status) {
        this.status = status;
    }

    private DefaultWorkReport(WorkStatus status, Throwable error) {
        this.status = status;
        this.error = error;
    }

    public static DefaultWorkReport valueOfError() {
        return new DefaultWorkReport(WorkStatus.FAILED);
    }

    public static DefaultWorkReport valueOfError(Throwable error) {
        return new DefaultWorkReport(WorkStatus.FAILED, error);
    }

    public static DefaultWorkReport valueOfOK() {
        return new DefaultWorkReport(WorkStatus.COMPLETED);
    }

    @Override
    public WorkStatus getStatus() {
        return status;
    }

    @Override
    public Throwable getError() {
        return error;
    }

    @Override
    public String toString() {
        return "DefaultWorkReport {" +
                "status=" + status +
                ", error=" + (error == null ? "''" : error) +
                '}';
    }
}
